package com.zsix.system.strategy.formMenu;

import com.zsix.system.mapper.formComponentsMapper.FormMenuMapper;
import com.zsix.system.mapper.menu.MenuMapper;
import com.zsix.common.entity.formComponents.FormMenuEntity;
import com.zsix.common.entity.menu.MenuEntity;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class FormMenu implements FormMenuStrategy {
    @Autowired
    private FormMenuMapper formMenuMapper;
    @Autowired
    private MenuMapper menuMapper;
    @Override
    public String setFormMenu(FormMenuEntity formMenuEntity){
        MenuEntity menu=formMenuEntity.getMenu();
        formMenuEntity.setIcon(menu.getIcon());
        formMenuEntity.setIsApplication(1);
        formMenuMapper.updateFormMenu(formMenuEntity);
        MenuEntity menuEntity=menuMapper.getMenu(formMenuEntity.getId());
        if(menuEntity!=null){
            menu.setIsFrame("0");
            menu.setStatus("1");
            menu.setVisible("1");
            menu.setMenuType("C");
            menu.setQuery(formMenuEntity.getId());
            menu.setMenuId(formMenuEntity.getId());
            menu.setUpdateTime(DateTime.now().toString("yyyy-MM-dd hh:mm:ss"));
            menuMapper.updayeMenu(menu);
        }
        else{
            menu.setIsFrame("0");
            menu.setStatus("1");
            menu.setVisible("1");
            menu.setMenuType("C");
            menu.setQuery(formMenuEntity.getId());
            menu.setCreateTime(DateTime.now().toString("yyyy-MM-dd hh:mm:ss"));
            menu.setMenuId(formMenuEntity.getId());
            menuMapper.addMenu(menu);
        }
        return "";
    }
    @Override
    public String depeteFormMenu(FormMenuEntity formMenuEntity){
        formMenuMapper.depeteFormMenu(formMenuEntity.getId());
        menuMapper.deleteMenu(formMenuEntity.getId());
        return "删除成功";
    }
    @Override
    public String getType(){
        return "0";
    }
}
